package com.wjpeng.wms.web.controller;

import com.wjpeng.wms.service.IEmployeeService;
import com.wjpeng.wms.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    @Autowired
    private IEmployeeService employeeService;



    @RequestMapping("login")
    @ResponseBody
    public Object login(String username,String password){
        //创建一个JSON结果的对象
        JSONResult result = new JSONResult();
        try {
            //传入username和password参数
            employeeService.login(username,password);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());//保存错误信息
        }

        return result;
    }


    @RequestMapping("main")
    public String main(){
        return "main";
    }

    @RequestMapping("logout")
    public String logout(HttpSession session){
        //销毁session
        session.invalidate();
        return "redirect:/login.jsp";
    }

    @RequestMapping("nopermission")
    public String nopermission(){
        return "common/nopermission";
    }

}
